function dt=read_data(pcr_file,clin_file)

%READ_DATA reads training PCR and clinical data provided for a classification chalange
%Syntax: train=read_data(pcr_file,clin_file)
%Description: this is a tailored function to read the data provided by
%             Kevin Coombes for the classification chalange. The file names
%             with the pcr and clinical data can be passed as input
%             arguments. Default values are otherwiese generated,
%             'normCtValues.tsv' and 'trainClinical.tsv'.
%
%Jonas Almeida, 2006 Feb 10

if nargin<2;clin_file='trainClinical.tsv';end
if nargin<1;pcr_file='normCtValues.tsv';end

%1. READ PCR DATA
fid=fopen(pcr_file,'r');

%Read header with sample names
lala=fgetl(fid);dt.sample_names=eval(['{''',regexprep(lala(2:end),'\t',''','''),'''}']);

%Read pcr data and and the gene names
dt.pcr_data=[];dt.pcr_gene='';
while ~feof(fid)
    lala=fgetl(fid);
    [a b c d e]=regexp(lala,'([^\t]+)\t(.*)');
    dt.pcr_gene=[dt.pcr_gene,e{1}(1)];
    dt.pcr_data=[dt.pcr_data;str2num(e{1}{2})];
end
dt.pcr_data=dt.pcr_data'; %transpose it into [cases x parms] layout

fclose(fid);

%2. READ CLINICAL DATA
fid=fopen(clin_file,'r');

%Read header with clinical/demographic variable names
lala=fgetl(fid);dt.clin_parms=eval(['{''',regexprep(lala(2:end),'\t',''','''),'''}']);

%Read data on clinical parameters
dt_clin_data='';
while ~feof(fid)
    lala=eval(['{''',regexprep(fgetl(fid),'\t',''','''),'''}']);
     i=strmatch(lala{1},dt.sample_names,'exact');
     if isempty(i);
         warning(['sample ",',lala{1},'" in clinical data set notfound in PCR results']);
     else
         disp([num2str(i),': ',lala{1}])
         dt.clin_data(i,:)=lala(2:end);
     end
end

fclose(fid);

%Prepare data for discriminant analysis
dt.x=dt.pcr_data;
U=unique(dt.clin_data(:,1));
dt.y=strcmp(dt.clin_data(:,1),U{1});
    
%Normalization
n=length(dt.x(:,1));
for i=1:n
    dt.nx(i,:)=memb(dt.x(i,:)')';
end

